n = int(input())
record = []
for _ in range(n):
    line = input().split()
    record.append(line)

dp = [0]*n
for i,line in enumerate(record):
    if int(line[1]) > 80 and int(line[5]) > 0:
        dp[i] += 8000
    if int(line[1]) > 85 and int(line[2]) > 80:
        dp[i] += 4000
    if int(line[1]) > 90:
        dp[i] += 2000
    if int(line[1]) > 85 and line[4] == "Y":
        dp[i] += 1000
    if int(line[2]) > 80 and line[3] == "Y":
        dp[i] += 850

maxn = max(dp)
sums = sum(dp)
index = dp.index(maxn)
print(record[index][0])
print(maxn)
print(sums)